﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using NDK.Module.DAL;
using NDK.Module.Model;
using NDK.Utils;

namespace NDK.Frm
{
    public partial class Frm_AutoCompensation : Form
    {
        MeasureSizeServices measureSizeServices = new MeasureSizeServices();
        private DataTable _dataTable = new DataTable();
        public Frm_AutoCompensation()
        {
            InitializeComponent();
        }
        public Frm_AutoCompensation(DataTable dt)
        {
            InitializeComponent();
            _dataTable = dt;
            dgv_AutoCompensation.DataSource = dt;
        }

        private void btn_Comfirm_Click(object sender, EventArgs e)
        {
            List<MeasureSize> measureSizeList = new List<MeasureSize>();
            for (int whichBlock = 0; whichBlock < 4; whichBlock++)
            {
                measureSizeList = measureSizeServices.GetAllByProjectNameAndTurnNum(Common.ProjectName, whichBlock);
                foreach (var measureSize in measureSizeList)
                {
                    measureSize.B += double.Parse(_dataTable.Rows[4][measureSize.SizeName].ToString());
                    measureSizeServices.Update(measureSize);
                }
            }
            
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_SaveCsv_Click(object sender, EventArgs e)
        {
            string savePath = "";
            //OpenFileDialog open = new OpenFileDialog();           //读取图片
            //open.CheckFileExists = true;
            //open.CheckPathExists = true;
            //open.Multiselect = false;
            //open.Filter = "CSV文件|*.csv;*";
            try
            {
                //if (open.ShowDialog() == DialogResult.OK)
                {
                    //savePath = open.FileName;
                    savePath = Common.dataSavePath + @"\AutoCompensation.csv";
                    if (savePath != "")
                    {
                        FileUtils.SaveCSV(_dataTable, savePath);
                    }
                }
            }
            catch
            {
                //m_Logger.Error("加载静态图片  -  button_OpenPic_Click Error:" + exc.Message);
            }
            
        }
    }
}
